/ Assembly List / LJCDBClientLib / DataManager / Add

Namespace - LJCDBClientLib


Parameters
dataObject - The record object.
propertyNames - The included column property names.

Returns

The result object.

Syntax

C#
public DbResult Add(Object dataObject, List<String> propertyNames = null)

Adds a record to the database. (RE)

Remarks

Parameters

propertyNames
This parameter defines the primary table column values that are to be added. If it is null, then all the primary table column values are added.
It must not include Calculated or Join columns or it will cause an error.

Creates an "Insert" DbRequest object, which is available in the Request property. The request object is passed to the ExecuteRequest() method.

The Key Columns are assigned from the LookupColumnNames property.

The Key Columns are those columns whose value will be used to find the added record. This is to return the DB Assigned column values to the calling program.

The Key Columns must include the DB Assigned columns for the assigned values to be returned to the calling program. The value must be set to zero to prevent including it as a key value?

The Lookup Retrieve call will not include keys with a value of "0".

The Add Data Object property names must be the same as the Request Column property names to map the values into the Key Columns.

Method Graph

All methods are in LJCDBMessage.DbCommon.

RequestDataColumns(dataObject)
RequestColumns(baseDefinition)
DataColumns(dataObject)
CreateValueColumn(dbColumn)
RequestLookupKeys(dataObject)
RequestColumns(baseDefinition)
LookupKeys(dataObject)
IsKeyColumn(dbColumn)

Example

C#
// This is an example of the Person Manager code that would access the
// DataManager Add() method. The supporting class code is listed at the
// DataManager class level.
    
using LJCNetCommon;
using LJCDBMessage;
    
/// <summary>Provides Person specific data manipulation methods.</summary>
public class PersonManager
{
  /// <summary>Adds a person record to the database.</summary>
  /// <param name="dataObject">The data record.</param>
  /// <param name="propertyNames">The included column property names.</param>
  /// <returns>A person object with the DB assigned key values.</returns>
  public Person Add(Person dataObject, List<string> propertyNames = null)
  {
    Person retValue = null;
    
    // The database assigned column names.
    mDataManager.SetDbAssignedColumnNames(new string[]
    {
      "Id"
    });
    
    // The lookup column names to find the inserted record for
    // the Add() method to retrieve the DB assigned column values.
    mDataManager.AddLookupColumnNames(new string[]
    {
      "Name"
    });
    
    DbResult dbResult = mDataManager.Add(dataObject, propertyNames);
    AffectedCount = mDataManager.AffectedCount;
    SQLStatement = mDataManager.SQLStatement;
    if (dbResult != null && dbResult.DbRecords.Count > 0)
    {
      // Populate a data object with the result values.
      retValue = new Person();
      DbCommon.SetObjectValues(dbResult.DbRecords[0], retValue);
    }
    
    int personId = retValue.PersonId;
    return retValue;
  }
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.